<extend name="Index/index"/>

<block name="box">
    <div class="view-product">
        <div class="info-center">
            <div class="manage-head">
                <h6 class="padding-left manage-head-con">{{$title}}</h6>
            </div>
        </div>
        <div class="layui-container" style="margin-top: 20px">
            <div class="layui-row">
                <if condition="empty($goodslist)">
                    <h2>暂无数据</h2>
                    <else/>
                    <table class="layui-table" id="table">
                        <colgroup>
                            <col width="50">
                            <col width="100">
                            <col width="100">
                        </colgroup>
                        <thead>
                        <tr>
                            <th>ID</th>
                            <th>名称</th>
                            <th>图片</th>
                            <th>种类</th>
                            <th>价格</th>
                            <th>库存</th>
                            <th>销售</th>
                            <th>上架</th>
                            <th>热销</th>
                            <th>新品</th>
                            <th>积分</th>
                            <th>积分数量</th>
                            <th id="action">操作</th>
                        </tr>
                        </thead>
                        <tbody>
                        <foreach name="goodslist" item="value">
                            <tr>
                                <td>{{$value.id}}</td>
                                <td>{{$value.name|subtext= ###,5}}</td>
                                <td><img src="{{$value.img}}"></td>
                                <td>{{$value.cname}}</td>
                                <td>{{$value.price}}</td>
                                <td>{{$value.num}}</td>
                                <td>{{$value.sales_num}}</td>
                                <td>
                                    <if condition="$value.is_show eq 0">
                                        <a class="layui-icon" style="font-size: 30px; color: red;" onclick="change_show('{{$value.is_show}}','{{$value.id}}',this)">&#x1006;</a>
                                    <else/>
                                        <a class="layui-icon" style="font-size: 30px; color: #1E9FFF;" onclick="change_show('{{$value.is_show}}','{{$value.id}}',this)">&#xe618;</a>
                                    </if>
                                    </td>
                                <td>
                                    <if condition="$value.is_hot eq 0">
                                        <a class="layui-icon" style="font-size: 30px; color: red;"onclick="change_hot('{{$value.is_hot}}','{{$value.id}}',this)">&#x1006;</a>
                                        <else/>
                                        <a class="layui-icon" style="font-size: 30px; color: #1E9FFF;"onclick="change_hot('{{$value.is_hot}}','{{$value.id}}',this)">&#xe618;</a>
                                    </if>
                                </td>
                                <td>
                                    <if condition="$value.is_new eq 0">
                                        <a class="layui-icon" style="font-size: 30px; color: red;"onclick="change_new('{{$value.is_new}}','{{$value.id}}',this)">&#x1006;</a>
                                        <else/>
                                        <a class="layui-icon" style="font-size: 30px; color: #1E9FFF;"onclick="change_new('{{$value.is_new}}','{{$value.id}}',this)">&#xe618;</a>
                                    </if>
                                </td>
                                <td>
                                    <if condition="$value.is_integral eq 0">
                                        <i class="layui-icon" style="font-size: 30px; color: red;">&#x1006;</i>
                                        <else/>
                                        <i class="layui-icon" style="font-size: 30px; color: #1E9FFF;">&#xe618;</i>
                                    </if>
                                </td>
                                <td>
                                    {{$value.integral_price}}
                                </td>
                                <td class="action">
                                    <a class="layui-btn layui-btn-sm layui-btn-normal"  href="{{:U('Goods/edit',array('id'=>$value['id']))}}">商品详情编辑</a>
                                    <a class="layui-btn layui-btn-sm layui-btn-normal"  href="{{:U('Goods/editImg',array('id'=>$value['id']))}}">商品图片编辑</a>

                                </td>
                            </tr>
                        </foreach>
                        <tr>
                            <td colspan="13"><div class="sabrosus">{{$page}}</div></td>
                        </tr>
                        </tbody>
                    </table>
                </if>
            </div>
        </div>
    </div>
    <script src="__PUBLIC__/Admin/Js/admin.js"></script>
    <script>
        //商品是否上架切换
        function change_show(show,id,obj){
            var url = "{{:U('Goods/change_show')}}";
            //alert("show");
            $.ajax({
                type : "post",
                url : url,
                data :{is_show:show, id:id},
                success : function(data){
                    console.log(data);
                    if(data == 0){
                        var text = '<i class="layui-icon" style="font-size: 30px; color: red;" onclick="change_show('+data+','+id+',this)">&#x1006;</i>'
                        var content = $(obj).parent().html(text);
                    }else if(data == 1){
                        var text = '<i class="layui-icon" style="font-size: 30px; color: #1E9FFF;" onclick="change_show('+data+','+id+',this)">&#xe618;</i>'
                        var content = $(obj).parent().html(text);
                    }
                }
            })
        }

        //商品是否热销切换
        function change_hot(hot,id,obj){
            var url = "{{:U('Goods/change_hot')}}";
            $.ajax({
                type : "get",
                url : url,
                data :{is_hot:hot,id:id},
                success : function(data){
                    console.log(data);
                    if(data == 0){
                        var text = '<i class="layui-icon" style="font-size: 30px; color: red;" onclick="change_hot('+data+','+id+',this)">&#x1006;</i>'
                        var content = $(obj).parent().html(text);
                    }else if(data == 1){
                        var text = '<i class="layui-icon" style="font-size: 30px; color: #1E9FFF;" onclick="change_hot('+data+','+id+',this)">&#xe618;</i>'
                        var content = $(obj).parent().html(text);
                    }
                }
            })
        }

        //商品是否新品切换
        function change_new(isnew,id,obj){
            var url = "{{:U('Goods/change_new')}}";
            $.ajax({
                type : "get",
                url : url,
                data :{is_new:isnew,id:id},
                success : function(data){
                    console.log(data);
                    if(data == 0){
                        var text = '<i class="layui-icon" style="font-size: 30px; color: red;" onclick="change_new('+data+','+id+',this)">&#x1006;</i>'
                        var content = $(obj).parent().html(text);
                    }else if(data == 1){
                        var text = '<i class="layui-icon" style="font-size: 30px; color: #1E9FFF;" onclick="change_new('+data+','+id+',this)">&#xe618;</i>'
                        var content = $(obj).parent().html(text);
                    }
                }
            })
        }

        //商品分类是否显示切换
        function change_category_show(show,id,obj){
            var url = "{{:U('Goods/change_category_show')}}"
            $.ajax({
                type : "get",
                url : url,
                data :{is_show:show,id:id},
                success : function(data){
                    if(data == 0){
                        var text = '<i class="layui-icon" style="font-size: 30px; color: red;" onclick="change_category_show('+data+','+id+',this)">&#x1006;</i>'
                        var content = $(obj).parent().html(text);
                    }else if(data == 1){
                        var text = '<i class="layui-icon" style="font-size: 30px; color: #1E9FFF;" onclick="change_category_show('+data+','+id+',this)">&#xe618;</i>'
                        var content = $(obj).parent().html(text);
                    }else{
                        alert(data);
                    }
                }
            })
        }

    </script>
</block>